<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:org:add']"
          >新增会员单位</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:org:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:org:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:org:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          disabled
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:org:export']"
          >缴费</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain

          icon="el-icon-download"
          size="mini"
          :disabled="single"
          @click="setUsalAccount"
          v-hasPermi="['system:org:down']"
          >设置成普通帐号</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="orgList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="机构名称" align="center" prop="memberOrgName" />

      <el-table-column label="审核状态" align="center" prop="memberOrgState" >
        <template slot-scope="scope">
            <el-tag type="info" v-if="scope.row.memberOrgState===0">未知</el-tag>
<el-tag type="success" v-if="scope.row.memberOrgState===1">是</el-tag>
<el-tag type="error" v-if="scope.row.memberOrgState===2">否</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="是否是专业机构" align="center" prop="isPro" >
   <template slot-scope="scope">
            <el-tag type="info" v-if="scope.row.isPro===0">未知</el-tag>
<el-tag type="success" v-if="scope.row.isPro===1">是</el-tag>
<el-tag type="error" v-if="scope.row.isPro===2">否</el-tag>
        </template>
        </el-table-column>
      <el-table-column
        label="支付时间"
        align="center"
        prop="memberOrgPayTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.memberOrgPayTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>

      <el-table-column label="所在城市" align="center" prop="city" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:org:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:org:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员单位对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="机构名称" prop="memberOrgName">
              <el-input
                v-model="form.memberOrgName"
                placeholder="请输入机构名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人" prop="memberOrgManager">
              <el-input
                v-model="form.memberOrgManager"
                placeholder="请输入法人"
              />
            </el-form-item>
          </el-col>
        </el-row>
 <el-row>
          <el-col :span="12">
         <el-form-item label="组织机构代码" prop="memberOrgSn">
          <el-input
            v-model="form.memberOrgSn"
            placeholder="请输入组织机构代码"
          />
        </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系方式" prop="memberOrgTel">
          <el-input v-model="form.memberOrgTel" placeholder="请输入联系方式" />
        </el-form-item>
          </el-col>
        </el-row>
 <el-row>
          <el-col :span="12">
        <el-form-item label="登录名" prop="memberOrgUsername">
          <el-input v-model="form.memberOrgUsername" placeholder="登录名" />
        </el-form-item>
          </el-col>
          <el-col :span="12">
           <el-form-item label="登录密码" prop="memberOrgPassword">
          <el-input
            v-model="form.memberOrgPassword"
           show-password
            placeholder="请输入机构密码"
          />
        </el-form-item>
          </el-col>
        </el-row>
<el-row>
          <el-col :span="12">
         <el-form-item label="是否是专业机构" prop="isPro">
           <el-switch
  v-model="form.isPro"
  active-color="#13ce66"
  inactive-color="#ff4949"
   active-value="1"
    inactive-value="2"
  >
</el-switch>

        </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="所在城市" prop="address">

           <el-select v-model="form.city" placeholder="请选择">
    <el-option
      v-for="item in cityList"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
        </el-form-item>
          </el-col>
        </el-row>





        <el-form-item label="备注信息" prop="prop">
          <el-input v-model="form.prop" placeholder="请输入备注信息" />
        </el-form-item>



      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrg,
  getOrg,
  delOrg,
  addOrg,
  updateOrg,
  down
} from "@/api/hnsdsa/memberorg/org";

export default {
  name: "Org",
  data() {
    return {
      cityList:[
        { value: '郑州市',
          label: '郑州市'},
            { value: '开封',
          label: '开封'},
            { value: '洛阳',
          label: '洛阳'},
            { value: '平顶山',
          label: '平顶山'},
            { value: '安阳',
          label: '安阳'},
            { value: '鹤壁',
          label: '鹤壁'},
            { value: '新乡',
          label: '新乡'},
            { value: '焦作',
          label: '焦作'},
            { value: '濮阳',
          label: '濮阳'},
            { value: '许昌',
          label: '许昌'},
            { value: '漯河',
          label: '漯河'},
            { value: '三门峡',
          label: '三门峡'},
         { value: '南阳',
          label: '南阳'},
             { value: '商丘',
          label: '商丘'},
             { value: '信阳',
          label: '信阳'},
             { value: '周口',
          label: '周口'},
             { value: '驻马店',
          label: '驻马店'},
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      orgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberOrgName: null,
        memberOrgType: null,
        memberOrgManager: null,
        memberOrgSn: null,
        memberOrgTel: null,
        memberOrgUsername: null,
        memberOrgState: null,
        memberOrgSignState: null,
        memberOrgPassword: null,
        loginIp: null,
        loginDate: null,
        delFlag: null,
        isPro: null,
        userId: null,
        createByUserName: null,
        memberOrgPayTime: null,
        prop: null,
        avatar: null,
        address: null,
        createByUserId: null,
        city: null,
        isProxyOrg: 1,
        ascriptionOrgId: null,
        ascriptionUserId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listOrg(this.queryParams).then((response) => {
        this.orgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        memberOrgName: null,
        memberOrgType: null,
        memberOrgManager: null,
        memberOrgSn: null,
        memberOrgTel: null,
        memberOrgUsername: null,
        memberOrgState: null,
        memberOrgSignState: null,
        memberOrgPassword: null,
        loginIp: null,
        loginDate: null,
        delFlag: null,
        isPro: null,
        userId: null,
        createByUserName: null,
        memberOrgPayTime: null,
        prop: null,
        avatar: null,
        address: null,
        createByUserId: null,
        city: null,
        isProxyOrg: null,
        ascriptionOrgId: null,
        ascriptionUserId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员单位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOrg(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员单位";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {

            updateOrg(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {

            addOrg(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除会员单位编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOrg(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/org/export",
        {
          ...this.queryParams,
        },
        `org_${new Date().getTime()}.xlsx`
      );
    },

   setUsalAccount(row){
        const id = row.id || this.ids;
  this.$modal
        .confirm('是否确认该会员单位为普通单位账号？')
        .then(function () {
          return down(id);
          // delOrg(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("设置成功");
        })
        .catch(() => {});
    }

  },
};
</script>
